home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / ifgate / attach.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-04  |  1.7 KB  |  89 lines

  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <limits.h>
  8. #include <sys/stat.h>
  9. #include "ftn.h"
  10. #include "lutil.h"
  11. #include "config.h"
  12.  
  13. #ifndef PATH_MAX
  14. #define PATH_MAX 512
  15. #endif
  16.  
  17. extern FILE *openflo(faddr *,char);
  18.  
  19. void try_attach(fn,mode,addr,flavor)
  20. char *fn;
  21. int mode;
  22. faddr *addr;
  23. char flavor;
  24. {
  25.     FILE *flo;
  26.     char pn[PATH_MAX],*p,*f;
  27.     struct stat stbuf;
  28.  
  29.     for (p=fn;*p;p++) if (*p == '\\') *p='/';
  30.  
  31.     f=fn;
  32.     while (isspace(*f)) f++;
  33.     strncpy(pn,f,sizeof(pn));
  34.     if (*(p=pn+strlen(pn)-1) == '\n') *(p--)='\0';
  35.     while (isspace(*p)) p--;
  36.  
  37.     debug(3,"Trying fileattach \"%s\" (mode %d) to %s (flavor %c)",
  38.         fn,mode,ascfnode(addr,0x1f),flavor);
  39.  
  40.     if (stat(pn,&stbuf) != 0)
  41.     {
  42.         for (p=pn;*p;p++) *p=tolower(*p);
  43.         if (stat(pn,&stbuf) != 0)
  44.         {
  45.             strncpy(pn,inbound,sizeof(pn)-1);
  46.             strcat(pn,"/");
  47.             p=pn+strlen(pn);
  48.             if ((f=strrchr(fn,'/'))) f++;
  49.             else f=fn;
  50.             while (isspace(*f)) f++;
  51.             strncpy(p,f,sizeof(pn)-strlen(pn));
  52.             if (*(p=pn+strlen(pn)-1) == '\n') *(p--)='\0';
  53.             while (isspace(*p)) p--;
  54.             if (stat(pn,&stbuf) != 0)
  55.             {
  56.                 for (p=pn;*p;p++) *p=tolower(*p);
  57.                 if (stat(pn,&stbuf) != 0)
  58.                 {
  59.                     loginf("$cannot stat \"%s\" attach to %s",
  60.                         fn,ascfnode(addr,0x1f));
  61.                     return;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     if ((flo=openflo(addr,flavor)) == NULL) return;
  68.  
  69.     if ((p=strrchr(fn,'/')))
  70.     {
  71.         while (*(++p)) *(fn++)=*p;
  72.         *(fn++)='\0';
  73.     }
  74.  
  75.     debug(3,"attaching file \"%s\" to node %s",pn,ascfnode(addr,0x1f));
  76.  
  77.     fseek(flo,0L,SEEK_END);
  78.     switch (mode)
  79.     {
  80.     case 0:    break;
  81.     case 1: fprintf(flo,"#"); break;
  82.     case 2: fprintf(flo,"^"); break;
  83.     }
  84.     fprintf(flo,"%s\n",pn);
  85.  
  86.     fclose(flo);
  87.     return;
  88. }
  89.